import React, { Component } from 'react';
import LoaderHelper from './loaderHelper';
import { NO_VIDEO_SRC } from '../../../../../../consts/consts';

class VideoLoader extends Component {
    componentDidMount() {
        const { widget } = this.props;
        let url = widget.action.video_thumbnail ? widget.action.video_thumbnail : NO_VIDEO_SRC;
        LoaderHelper.preloadImage(url, widget, false, true, false);
    }
    componentWillReceiveProps(nextProps) {
    	if (nextProps.widget !== this.props.widget) {
    		LoaderHelper.resetMeshItem(nextProps.widget, this.updateMedia)
    	}
    }

    updateMedia(data) {
        var url = data.action.video_thumbnail || data.url;
        if (url){
            data.url = url;
            LoaderHelper.imageGeometryLoader(null, data, true);
        }
    }

    render() {
        return (<div />)
    }
}

export default VideoLoader;
